//
//  OrigPubAddConceptPhotoTextCell.m
//  ShrimpCrowdordering
//
//  Created by jimmy on 2018/8/29.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrigPubAddConceptPhotoTextCell.h"

@interface OrigPubAddConceptPhotoTextCell ()<UITextViewDelegate>
{
    CGFloat _cellHeight;
}

@property (nonatomic, strong) NSIndexPath * indexPath;
@property (nonatomic, strong) UILabel * imageTitleLab;
@property (nonatomic, strong) UILabel * connectTitleLab;
@property (nonatomic, strong) UIImageView * imageV;
@property (nonatomic, strong) UIButton * selectBtn;
@property (nonatomic, strong) UITextView * textView;
@end

@implementation OrigPubAddConceptPhotoTextCell

+ (id)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath andCellHeight:(CGFloat)height
{
    static NSString *cellID = @"OrigPubAddConceptPhotoTextCell";
    OrigPubAddConceptPhotoTextCell *cell = [[OrigPubAddConceptPhotoTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID andIndexPath:indexPath andCellHeight:height];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier andIndexPath:(NSIndexPath *)indexPath andCellHeight:(CGFloat)height
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _cellHeight = height;
        self.indexPath = indexPath;
        [self setUIView];
    }
    
    return self;
}

- (void)setUIView
{
    self.imageTitleLab = [[UILabel alloc] init];
    self.imageTitleLab.font = [UIFont boldSystemFontOfSize:18];
    [self addSubview:self.imageTitleLab];
    
    UIView * bjView = [[UIView alloc] init];
    bjView.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    bjView.layer.cornerRadius = 9;
    bjView.layer.masksToBounds = YES;
    bjView.clipsToBounds = YES;
    [self addSubview:bjView];
    
    self.imageV = [[UIImageView alloc] init];
    [bjView addSubview:self.imageV];
    
    self.selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    self.selectBtn.contentMode = UIViewContentModeScaleAspectFill;
    [self.selectBtn setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
    [self.selectBtn addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside];
    [bjView addSubview:self.selectBtn];
    
    UILabel * noteLab = [[UILabel alloc] init];
    noteLab.textColor = [UIColor redColor];
    noteLab.font = [UIFont systemFontOfSize:12];
    [self addSubview:noteLab];
    
    self.connectTitleLab = [[UILabel alloc] init];
    self.connectTitleLab.font = [UIFont boldSystemFontOfSize:18];
    [self addSubview:self.connectTitleLab];
    
    self.textView = [[UITextView alloc] init];

    self.textView.delegate = self;
    self.textView.font = [UIFont systemFontOfSize:15];
    self.textView.layer.cornerRadius = 9;
    self.textView.layer.masksToBounds = YES;
    self.textView.layer.borderColor = [[UIColor grayColor] CGColor];
    self.textView.layer.borderWidth = 1;
    [self addSubview:self.textView];
    
    self.imageTitleLab.frame    = CGRectMake(ScreenX375(16), ScreenX375(20), SCREEN_WIDTH - ScreenX375(32), ScreenX375(20));
    bjView.frame                = CGRectMake(ScreenX375(31), ScreenX375(60), SCREEN_WIDTH - ScreenX375(62), ScreenX375(120));
    self.imageV.frame           = CGRectMake(0, 0, SCREEN_WIDTH - ScreenX375(62), ScreenX375(120));
    self.selectBtn.frame        = CGRectMake(0, 0, SCREEN_WIDTH - ScreenX375(62), ScreenX375(120));
    noteLab.frame               = CGRectMake(ScreenX375(31), ScreenX375(180)+ScreenX375(13), SCREEN_WIDTH - ScreenX375(62), ScreenX375(12));
    self.connectTitleLab.frame  = CGRectMake(ScreenX375(16), ScreenX375(220), SCREEN_WIDTH - ScreenX375(32), ScreenX375(20));
    self.textView.frame         = CGRectMake(ScreenX375(31), ScreenX375(260), SCREEN_WIDTH - ScreenX375(62), ScreenX375(120));
    
    self.imageTitleLab.text = @"新增图片";
    self.connectTitleLab.text = @"新增设计理念";
    noteLab.text = @"注:只能上传一张";
    self.textView.placeHoldString = @"请输入新增设计理念内容";
    
}

- (void)hiddenBtnImage:(BOOL)isHidden
{
    if (isHidden) {
        [self.selectBtn setImage:[UIImage new] forState:UIControlStateNormal];
    }else{
        [self.selectBtn setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
    }
}

- (void)textViewResignFirstResponder
{
    [self.textView resignFirstResponder];
}

- (void)setImageWith:(AddConceptModel *)model
{
    if (model == nil) {
        return;
    }
    self.imageV.image = model.picImage;
//    [self.imageV sd_setImageWithURL:[NSURL URLWithString:model.pic]];
    self.textView.text = model.idea;
}

- (void)setImageViewWithImage:(UIImage *)image
{
    if (!image) {
        return;
    }
    self.imageV.image = image;
}

- (void)selectAction{
    if (self.btnSelectBlock) {
        self.btnSelectBlock(self.indexPath);
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if (self.textViewBegEdBlock) {
        self.textViewBegEdBlock(self.indexPath);
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if (self.textViewEndEdBlock) {
        self.textViewEndEdBlock(self.textView.text, self.indexPath);
    }
}


@end

@implementation AddConceptModel


@end
